﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DCT.AutoUpdate.Code.EventTrigger
{
    public class EventTrigger<TArgument>
    {
        private List<Func<TArgument, bool>> triggers;

        public EventTriggerOutter<TArgument> TriggerOutter { get; private set; }

        private EventTrigger()
        {
            this.triggers = new List<Func<TArgument, bool>>();
            this.TriggerOutter = new EventTriggerOutter<TArgument>(triggers);
        }

        public void Fire(TArgument arg) {
            foreach (var item in this.triggers)
            {
                bool iscontinue = item(arg);
                if (!iscontinue) {
                    break;
                }
            }
        }

        public void Clear() {
            this.triggers.Clear();
        }

        public static EventTrigger<TArgument> CreateInstance()
        {
            return new EventTrigger<TArgument>();
        }
    }
}
